using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Publicuse.Entity;
using Publicuse.Util;

namespace Publicuse.Export
{
  /// <summary>
  /// 权限资源信息辅助类
  /// </summary>
  public class MenuExport
  {
    /// <summary>
    /// 权限资源导出数据设置
    /// </summary>
    /// <param name="excelName"></param>
    /// <param name="fileName"></param>
    /// <param name="list"></param>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static MemoryStream ExportData(
      string fileName,
      string excelName,
      List<Menu> list,
      out string msg
    )
    {
      msg = string.Empty;
      MemoryStream ms = ExcelUtil.GetExcelUtil.InitExportData(
        fileName,
        excelName,
        list,
        (row, cell, sheet1, TextSytle, srow, hssfworkbook) =>
        {
          foreach (Menu item in list)
          {
            srow++;
            row = sheet1.CreateRow(srow);

            //资源编码
            cell = row.CreateCell(0);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.aCode);

            //资源名称
            cell = row.CreateCell(1);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.aName); //区域ID

            //资源类型
            cell = row.CreateCell(2);
            cell.CellStyle = TextSytle;
            string typename = string.Empty;
            switch (item.aType)
            {
              case 1:
                typename = "模块";
                break;
              case 2:
                typename = "菜单";
                break;
              case 3:
                typename = "按钮";
                break;
              default:
                typename = "未知";
                break;
            }
            cell.SetCellValue(typename);

            //资源页面
            cell = row.CreateCell(3);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.ahtmlUrl);

            //资源页面图标
            cell = row.CreateCell(4);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.ahtmlIcon);

            //资源接口
            cell = row.CreateCell(5);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.aapiUrl);

            //资源状态
            cell = row.CreateCell(6);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.status == 1 ? "启用" : "停用");
          }
        },
        out msg,
        2
      );
      return ms;
    }
  }
}
